#!/usr/bin/python

import requests
import re
import time
import random

url_0 = "http://www.adopteunmec.com/index"
url = "http://www.adopteunmec.com//auth/login"
data = {"username": "login", "password": "pass"}

deja_visite = []
recherche = "age%5Bmin%5D=24&age%5Bmax%5D=35&age_step=1&by=region&country=fr&region=11&distance%5Bmin%5D=&distance%5Bmax%5D=1000&distance_step=10&pseudo=&sex=1&size%5Bmin%5D=120&size%5Bmax%5D=220&size_step=5&weight%5Bmin%5D=30&weight%5Bmax%5D=115&weight_step=5&mandatory%5B%5D=shape&mandatory%5B%5D=eyes_color&mandatory%5B%5D=origins&mandatory%5B%5D=hair_color&mandatory%5B%5D=hair_size&mandatory%5B%5D=hair_style&mandatory%5B%5D=styles&mandatory%5B%5D=character&mandatory%5B%5D=features&mandatory%5B%5D=diet&mandatory%5B%5D=favourite_food&mandatory%5B%5D=tobacco&mandatory%5B%5D=alcohol"

rechall = "age%5Bmin%5D=24&age%5Bmax%5D=37&age_step=1&by=region&country=fr&region=&distance%5Bmin%5D=&distance%5Bmax%5D=1000&distance_step=10&pseudo=&sex=1&size%5Bmin%5D=120&size%5Bmax%5D=220&size_step=5&weight%5Bmin%5D=30&weight%5Bmax%5D=115&weight_step=5&mandatory%5B%5D=shape&mandatory%5B%5D=eyes_color&mandatory%5B%5D=origins&mandatory%5B%5D=hair_color&mandatory%5B%5D=hair_size&mandatory%5B%5D=hair_style&mandatory%5B%5D=styles&mandatory%5B%5D=character&mandatory%5B%5D=features&mandatory%5B%5D=diet&mandatory%5B%5D=favourite_food&mandatory%5B%5D=tobacco&mandatory%5B%5D=alcohol"

rnd = 1
renew = 0
j = 0

while True :
	print("round : "+str(rnd))
	s = requests.session()
	r = s.get(url_0,headers={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"})
	time.sleep(random.randint(2,5))
	r = s.post(url, data, allow_redirects=True,headers={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"})
	time.sleep(random.randint(2,4))

	rnd = rnd + 1
	url_rech = "http://www.adopteunmec.com/mySearch/"
	r = s.post(url_rech,rechall,headers={"Origin":"http://www.adopteunmec.com","Accept-Charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.3","Content-Type":"application/x-www-form-urlencoded","User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"})

	i = 1
	patt = re.compile("\"id\":\"(\d+)\"")
	while i <= 16 :
		url_rech = "http://www.adopteunmec.com/mySearch/?page="+str(i)
		r = s.get(url_rech,headers={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"})
		ids = patt.findall(r.text)
		for id_girl in ids :
			if id_girl not in deja_visite :
				url_v = "http://www.adopteunmec.com/profile/"+id_girl
				print(url_v)
				r = s.get(url_v,headers={"User-Agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko)"})
				deja_visite.append(id_girl)
				time.sleep(random.randint(3,7))
			else :
				print("deja vue !")
		i = i + 1
		time.sleep(random.randint(1,3))
	del(s)
	time.sleep(random.randint(60,120))
